import { createSSRApp } from 'vue'
import 'virtual:svg-icons-register'

import uviewPlus from 'uview-plus'
import * as Pinia from 'pinia'
import store from '@/store/store'
import App from '@/App.vue'

import XModal from '@/components/Modal/index.vue'
import XNavBar from '@/components/NavBar/index.vue'
import XTabBar from '@/components/TabBar/index.vue'
import XNothing from '@/components/Nothing/index.vue'
import XPicture from '@/components/Picture/index.vue'
import XPickerPopup from '@/components/PickerPopup/index.vue'
import XSuccessIcon from '@/components/successIcon/index.vue'
import XNavigateBackIcon from '@/components/NavigateBackIcon/index.vue'
import SvgIcon from '@/components/SvgIcon/index.vue'
import ConditionFilter from '@/components/ConditionFilter/ConditionFilter.vue'
import Question from '@/components/Modals/question.vue'
import lRadio from '@/components/lForm/lRadio.vue'
import lSelect from '@/components/lForm/lSelect.vue'
import lUploadImg from '@/components/lForm/lUploadImg.vue'
import lInput from '@/components/lForm/lInput.vue'
import lIntro from '@/components/lForm/lIntro.vue'
import lNumber from '@/components/lForm/lNumber.vue'
import lLimit from '@/components/lForm/lLimit.vue'
import UnderDevelopment from '@/components/UnderDevelopment/index.vue'
export function createApp() {
  const app = createSSRApp(App)

  app.config.compilerOptions.isCustomElement = (tag) => {
    return tag.startsWith('wx-open-launch-weapp')
  }
  app.directive('alive', (el, value) => {
    const { permission } = uni.getStorageSync('userToken_zh_web')
    let pers = []
    if(!permission) return
    permission.forEach((item) => {
      pers.push(item.id)
      item.children.forEach((i) => {
        pers.push(i.id)
      })
    })
    if (!pers.includes(value.value)) {
      el?.parentNode?.removeChild(el)
    }
  })

  app.use(Pinia.createPinia())
  app.use(uviewPlus)
  app.component('XModal', XModal)
  app.component('XNavBar', XNavBar)
  app.component('XTabBar', XTabBar)
  app.component('XNothing', XNothing)
  app.component('XPicture', XPicture)
  app.component('XSuccessIcon', XSuccessIcon)
  app.component('XPickerPopup', XPickerPopup)
  app.component('XNavigateBackIcon', XNavigateBackIcon)
  app.component('SvgIcon', SvgIcon)
  app.component('ConditionFilter', ConditionFilter)
  app.component('Question', Question)
  app.component('lRadio', lRadio)
  app.component('lSelect', lSelect)
  app.component('lUploadImg', lUploadImg)
  app.component('lInput', lInput)
  app.component('lIntro', lIntro)
  app.component('lNumber', lNumber)
  app.component('lLimit', lLimit)
  app.component('UnderDevelopment', UnderDevelopment)
  store.initStore()
  return {
    app,
    Pinia,
  }
}
